package com.woniuxy02;

import java.io.*;
//是你（继承关系，兼容类型）还有你（子类定义父类的成员变量），一切拜托你
class Coffee{
    public String getCoffe(){
        return "coffee";
    }
}

class SaltCoffee extends Coffee{
    Coffee coffee;

    public SaltCoffee(Coffee coffee){
        this.coffee = coffee;
    }

    public String getCoffe(){
        return "salt,"+coffee.getCoffe();
    }
}
class SugarCoffee extends Coffee{

    Coffee coffee;

    public SugarCoffee(Coffee coffee){
        this.coffee = coffee;
    }
    public String getCoffe(){
        return "sugar,"+coffee.getCoffe();
    }
}
class MilkCoffee extends Coffee{
    Coffee coffee;

    public MilkCoffee(Coffee coffee){
        this.coffee = coffee;
    }

    public String getCoffe(){
        return "milk,"+coffee.getCoffe();
    }
}


public class Test06 {
    public static void main(String[] args) throws FileNotFoundException {
//        BufferedInputStream bis=new BufferedInputStream(new FileInputStream("a.txt"));
//
//        InputStreamReader isr=new InputStreamReader(new FileInputStream("a.txt"));
//
//        BufferedReader br=new BufferedReader(new InputStreamReader(new FileInputStream("a.txt")));

        //装饰者模式，包装器，XxxxWrapper
        //对类的功能增强

        Coffee coffee = new Coffee();
        System.out.println(coffee.getCoffe());
        SugarCoffee coffee1 = new SugarCoffee(coffee);
        System.out.println(coffee1.getCoffe());
        MilkCoffee coffee2 = new MilkCoffee(coffee1);
        System.out.println(coffee2.getCoffe());

        System.out.println(new SaltCoffee(new SaltCoffee(new MilkCoffee(new Coffee()))).getCoffe());
    }
}
